$(document).ready(function() {
    //$.cookie("animation-tree", "false");

    if ( $.cookie("animation-tree") != "viewed" ) {
        var height = $(window).height();
 
        var width  = $(window).width();

        var divTree = $('<div id="animation-tree"></div>')
        .css({
	   'position': 'absolute',
	   'left': 0,
	   'top': 0,
	   'width': width,
	   'height': height,
	   'background-color': 'black'
        })
        .appendTo('body');

        var divTreeLeft = $('<div class="left"></div>')
        .css({
	   'position': 'absolute',
	   'left': 0,
	   'top': 0,
	   'width': Math.round(width/2),
	   'height': height,
	   'background': 'url(web/css/images/tree-left.png) center right no-repeat'
        })
        .appendTo(divTree);

        var divTreeRight = $('<div class="right"></div>')
        .css({
	   'position': 'absolute',
	   'left': Math.round(width/2),
	   'top': 0,
	   'width': Math.round(width/2),
	   'height': height,
	   'background': 'url(web/css/images/tree-right.png) center left no-repeat'
        })
        .appendTo(divTree);


        $(window).load(function(){
	   setTimeout(function(){
	       var height = $(window).height();
	 
	       var width  = $(window).width();
	       var divTree = $('#animation-tree');

	       divTree.css('background', 'none');

	       var bar = $('<div></div>')
	       .css({
		  'position': 'absolute',
		  'top': Math.round(height/2),
		  'left': Math.round(width/2)-1,
		  'height': 0,
		  'border-right': '2px solid #fff'
	       })
	       .appendTo('body')
	       .animate({
		  'height': height,
		  'top': 0
	       },1000, 'easeInExpo',

	       function() {

		  bar.remove();

		  divTree.find('.left')
		  .css({
		      'width': Math.round(width/2)-1,
		      'border-right':'1px solid #fff',
		      'box-shadow':'-1px 0 5px #000'
		  })
		  .animate({
		      'left':-Math.round(width/2),
		      'width':0,
		      opacity:0
		  },1500, 'easeInExpo', function() {
		      $(this).remove();
		      divTree.remove();
		  });

		  divTree.find('.right')
		  .css({
		      'width': Math.round(width/2)-1,
		      'border-left': '1px solid #fff',
		      'box-shadow':'1px 0 5px #000'
		  })
		  .animate({
		      'left':width-5,
		      'width':0,
		      opacity:0
		  },1500, 'easeInExpo', function() {
		      $(this).remove();
		      divTree.remove();

		      $.cookie("animation-tree", "viewed", {
			 expires:7
		      });

		  });

		  bar.remove();
	       });
	   }, 1000);
        });
        }// end if cookie
   

});
